package com.hongye.customer.service.impl;

import com.hongye.common.entity.OrderEntity;
import com.hongye.customer.mapper.CustomerMapper;
import com.hongye.customer.service.OrderService;
import com.hongye.customer.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public String updateOrderStatus(String out_trade_no, String trade_no, String total_amount) {
        customerMapper.updateOrderStatus(out_trade_no,trade_no,total_amount);
        return "success";
    }

    /**
     * 获取当前订单的支付信息
     * @param orderId
     * @return
     */
    @Override
    public PayVo getOrderById(String orderId) {
        //1.获取当前订单的支付信息
        PayVo payVo = new PayVo();
        OrderEntity orderEntity = customerMapper.getById(orderId);
        payVo.setOut_trade_no(orderEntity.getId());
        BigDecimal payment = orderEntity.getPayment().setScale(2, BigDecimal.ROUND_UP);
        payVo.setTotal_amount(payment.toString());
        return payVo;
    }
}